#pragma once

#include "../../../include/p2p_interface.hpp"
#include "../../../include/net_interface.hpp"
#include "../../../include/timer_interface.hpp"

#include "P2PSessionManager.h"
#include "TimerManager.h"
#include "P2PProtocolImpl.h"

#define UNKNOW_NAT                  0
#define FULL_CONE_NAT               1
#define RESTRICTED_CONE_NAT         2
#define PORT_RESTRICTED_CONE_NAT    3
#define SYMMETRIC_NAT               4

class CP2P :
    public IP2P
{
public:
    CP2P(void);
    virtual ~CP2P(void);

    bool Init(IP2PSessionManager* p2p_session_manager);
    void UnInit(void);
    virtual bool Login(const char* p2p_server_ip, const UINT16 p2p_server_port, const UINT16 p2p_nat_test_port);
    virtual bool AddPeer(UINT32 peer_p2p_id);
    virtual void DelPeer(UINT32 peer_p2p_id);
    virtual bool SendPeer(UINT32 peer_p2p_id, const char* pData, const INT32 iLen);
    virtual void SetPeerUserData(UINT32 peer_p2p_id, void* user_data);
    virtual void* GetPeerUserData(UINT32 peer_p2p_id);
    virtual bool Run(void);

    bool Open(UINT32 ip, UINT16 port);

    DEFREFMEMBER(CP2PSessionManager, m_p2p_session_manager, p2p_session_manager)
    DEFREFMEMBER(CP2PTimerManager, m_p2p_timer_manager, p2p_timer_manager)
    DEFREFMEMBER(CHostSession, m_host, host)
    DEFREFMEMBER(CHostCheck, m_host_check, host_check)
    DEFREFMEMBER(CP2PProtocolImpl, m_p2p_protocol_impl, p2p_protocol_impl)
    DEFMEMBER(INetManager*, m_net_manager, net_manager)
    DEFMEMBER(ITimerManager*, m_timer_manager, timer_manager)
    DEFMEMBER(IP2PSessionManager*, m_p2p_session_call_back, p2p_session_call_back)
    DEFMEMBER(UINT32, m_p2p_id, p2p_id)
    DEFMEMBER(UINT16, m_nat_test_port, nat_test_port)
    DEFREFMEMBER(CSvrPacketParser, m_pkg_parser, pkg_parser)
    DEFMEMBER(CP2PSession*, m_current_p2p_session, current_p2p_session)
    DEFMEMBER(CHostSession*, m_current_host_session, current_host_session)
    DEFMEMBER(UINT16, m_nat_type, nat_type)
    DEFMEMBER(HNETHANDLE, m_listener, listener)
};
